<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\BaseGoodsQg;

/**
 * BaseGoodsQgSearch represents the model behind the search form about `app\models\BaseGoodsQg`.
 */
class BaseGoodsQgSearch extends BaseGoodsQg
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['qgd_id', 'status', 'qgsl', 'xj', 'cs', 'qym', 'statuses', 'sp_id'], 'integer'],
            [['qgczrz', 'spm', 'gg', 'bzqyq', 'dhrq', 'wlsyq', 'fbsj', 'mjgs', 'mjgsdz', 'mjlxr', 'mjlxrdh', 'mjshdz'], 'safe'],
            [['sczdj', 'cgjg'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = BaseGoodsQg::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'qgd_id' => $this->qgd_id,
            'status' => $this->status,
            'sczdj' => $this->sczdj,
            'qgsl' => $this->qgsl,
            'cgjg' => $this->cgjg,
            'xj' => $this->xj,
            'cs' => $this->cs,
            'qym' => $this->qym,
            'statuses' => $this->statuses,
            'sp_id' => $this->sp_id,
        ]);

        $query->andFilterWhere(['like', 'qgczrz', $this->qgczrz])
            ->andFilterWhere(['like', 'spm', $this->spm])
            ->andFilterWhere(['like', 'gg', $this->gg])
            ->andFilterWhere(['like', 'bzqyq', $this->bzqyq])
            ->andFilterWhere(['like', 'dhrq', $this->dhrq])
            ->andFilterWhere(['like', 'wlsyq', $this->wlsyq])
            ->andFilterWhere(['like', 'fbsj', $this->fbsj])
            ->andFilterWhere(['like', 'mjgs', $this->mjgs])
            ->andFilterWhere(['like', 'mjgsdz', $this->mjgsdz])
            ->andFilterWhere(['like', 'mjlxr', $this->mjlxr])
            ->andFilterWhere(['like', 'mjlxrdh', $this->mjlxrdh])
            ->andFilterWhere(['like', 'mjshdz', $this->mjshdz]);

        return $dataProvider;
    }
}
